using System;
using System.Collections.Generic;
using System.Text;


namespace UmassGrader
{
    /// <summary>
    /// contains all the information about an enrolled student
    /// </summary>
    [Serializable]
    public class Student
    {
        /// <summary>
        /// the username of the student (used to find their folder)
        /// </summary>
        public String userName;
        /// <summary>
        /// the first name of the student
        /// </summary>
        public String fName;
        /// <summary>
        /// the last name of the student
        /// </summary>
        public String lName;
        /// <summary>
        /// enumerated value representing what day the student has lab
        /// </summary>
        public DayOfWeek LabSection;
        /// <summary>
        /// is the student enrolled
        /// </summary>
        public bool enrolled;
        /// <summary>
        /// Depreciated dont use anymore
        /// </summary>
        public string picturePath;

        /// <summary>
        /// construct a fake student
        /// </summary>


        public Student()
        {
            userName = "jdoe";
            fName = "jon";
            lName = "doe";
            LabSection = DayOfWeek.Monday;
            enrolled = true;
            picturePath = "No File";
        }


        /// <summary>
        /// construct student based only on their userName
        /// </summary>
        public Student(string userName)
    {
        this.userName = userName;
        if (userName.StartsWith("u_"))
        {
            fName = userName.Substring(3, 1); // Mid(userName, 3, 1);
            lName = userName.Substring(4);    // Mid(userName, 4);
        }
        else
        {
            fName = userName.Substring(1, 1); // Mid(userName, 1, 1);
            lName = userName.Substring(2);    // Mid(userName, 2);
        }
        
        lName = lName.Trim('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');

        LabSection = DayOfWeek.Monday;
        enrolled = true;
        picturePath = "No File";
    }
        /// <summary>
        /// construct student from file stream
        /// </summary>

        public Student(System.IO.StreamReader infile)
            :this()
        {
            if (infile != null) initialize(infile.ReadLine());
        }



        /// <summary>
        /// fill in values for student based on string data
        /// </summary>
        /// <param name="datastring">contains all data pertaining to a student (see Class remarks for format)</param>
        public void initialize(string datastring)
        {
            //this method demonstrates the LAME way to do bounds checking... sugestions would be appreciated
            string[] mylst;
            mylst = datastring.Split(',');
            int count = mylst.Length;
            if (count >= 1) userName = mylst[0];
            if (count >= 2) lName = mylst[1];
            if (count >= 3) fName = mylst[2];
            if (count >= 4) LabSection = (DayOfWeek)Enum.Parse(typeof(DayOfWeek), mylst[3]);
            if (count >= 5) enrolled = Boolean.Parse(mylst[4]);
        }

        /// <summary>
        /// gives the Full name of a student
        /// </summary>
        /// <returns>A <see cref="T:System.String"></see> that represents the current <see cref="T:System.Object"></see>.</returns>
        public override string ToString()
        {
            return fullName;
        }

        /// <summary>
        /// serialize a instance to a CSV string
        /// </summary>
        public string serialize()
        {
            string str;
            str = userName + "," + lName + "," + fName + "," + LabSection.ToString() + "," +
                  enrolled.ToString() + "," + picturePath;
            return str;
        }

        /// <summary>
        /// is the student withdrawn
        /// </summary>
        public bool Withdrawn
        {
            get { return !enrolled; }
            set { enrolled = !value; }
        }

        /// <summary>
        /// the first and last name of a student
        /// </summary>
        public string fullName
        {
            get { return fName + " " + lName; }
        }
        /// <summary>
        /// is the student in a particular lab section
        /// </summary>
        /// <param name="day">a day of the week</param>
        public bool isSection(DayOfWeek day)
        {
            return day == this.LabSection;
        }
    }

}

